#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint kq_flutter_core_widget.podspec` to validate before publishing.
#


current_dir = Dir.pwd
calling_dir = File.dirname(__FILE__)
# def resolve_path(parent, relative_path)
#   # 移除路径中的 './'
#   cleaned_path = relative_path.gsub(/^\.\//, '')
#   # 使用 File.expand_path 将相对路径转换为绝对路径
#   File.expand_path(cleaned_path, parent)
# end
if calling_dir.include?('/.ios/.symlinks')
  flutter_project_dir = calling_dir.slice(0..(calling_dir.index('/.ios/.symlinks')))

  psych_version_gte_500 = Gem::Version.new(Psych::VERSION) >= Gem::Version.new('5.0.0')
  if psych_version_gte_500 == true
    cfg = YAML.load_file(File.join(flutter_project_dir, 'pubspec.yaml'), aliases: true)
  else
    cfg = YAML.load_file(File.join(flutter_project_dir, 'pubspec.yaml'))
  end
  if cfg['kq_flutter_core_widget']
    wx_app_id = cfg['kq_flutter_core_widget']['ios_wx_app_id']
    qq_app_id = cfg['kq_flutter_core_widget']['ios_qq_app_id']
    dd_app_id = cfg['kq_flutter_core_widget']['ios_dd_app_id']
    universal_link = cfg['kq_flutter_core_widget']['ios_app_link']
    if cfg['kq_flutter_core_widget']['ios_project_path']
        path = cfg['kq_flutter_core_widget']['ios_project_path']

        cleaned_path = path.gsub(/^\.\//, '')
        # 使用 File.expand_path 将相对路径转换为绝对路径
        project_dir = File.expand_path(cleaned_path, flutter_project_dir)
        # resolve_path(flutter_project_dir, path)
        if cfg['kq_flutter_core_widget']['ios_project_name']
            project_name = cfg['kq_flutter_core_widget']['ios_project_name']
            system("ruby #{current_dir}/setup.rb -w #{wx_app_id} -q #{qq_app_id} -d #{dd_app_id} -u #{universal_link} -p #{project_dir} -n #{project_name}.xcodeproj")
        end
    else
        project_dir = calling_dir.slice(0..(calling_dir.index('/.symlinks')))
        system("ruby #{current_dir}/setup.rb -w #{wx_app_id} -q #{qq_app_id} -d #{dd_app_id} -u #{universal_link} -p #{project_dir} -n Runner.xcodeproj")
    end
  end
end


Pod::Spec.new do |s|
  s.name             = 'kq_flutter_core_widget'
  s.version          = '0.0.1'
  s.summary          = 'A new Flutter project.'
  s.description      = <<-DESC
A new Flutter project.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.platform = :ios, '11.0'

  s.resource = ['TZImagePickerController.bundle']
  s.dependency 'AliyunOSSiOS', '~> 2.10.11'
  s.dependency 'AMapLocation', '~> 2.6.7'
  s.dependency 'ReactiveObjC', '~> 3.1.0'
  s.dependency 'WMZDialog','~> 1.4.99'
  s.dependency 'WechatOpenSDK', '~> 1.8.7.1'
  # Flutter.framework does not contain a i386 slice.

  s.vendored_frameworks = 'Libraries/*.framework'
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
end

